/*********************************************************************************************************
 *  ------------------------------------------------------------------------------------------------------
 *  file description
 *  ------------------------------------------------------------------------------------------------------
 *         \file  stack.h
 *        \brief  This is a general-purpose C language stack module, with circular mode and common data structure
 *       \author  Lamdonn
 *        \email  Lamdonn@163.com
 *      \version  1.1.0
 *      \license  GPL2
 *    \copyright  Copyright (C) 2023 Lamdonn.
 ********************************************************************************************************/
#include "vlib.h"

#define IDENT                           (3)

int stack_init(stack_t stack, void* array, int dsize, int capacity)
{
    int ret = deque_init((deque_t)stack, array, dsize, capacity);
    if (!ret) return 0;
    ((deque_t)stack)->parent.ident = IDENT;
    return ret;
}

void stack_deinit(stack_t stack)
{
    deque_deinit((deque_t)stack);
}

stack_t stack_create(int dsize, int capacity)
{
    stack_t stack = (stack_t)deque_create(dsize, capacity);
    if (!stack) return NULL;
    ((deque_t)stack)->parent.ident = IDENT;
    return stack;
}

void stack_delete(stack_t stack)
{
    deque_delete((deque_t)stack);
}

int stack_empty(stack_t stack)
{
    return deque_empty((deque_t)stack);
}

int stack_full(stack_t stack)
{
    return deque_full((deque_t)stack);
}

int stack_size(stack_t stack)
{
    return deque_size((deque_t)stack);
}

int stack_push(stack_t stack, void* data)
{
    return deque_push_back((deque_t)stack, data);
}

int stack_pop(stack_t stack, void* data)
{
    return deque_pop_back((deque_t)stack, data);
}

void stack_clear(stack_t stack)
{
    deque_clear((deque_t)stack);
}

void* stack_data(stack_t stack, int index, int orgin)
{
    return deque_data((deque_t)stack, index, orgin);
}

int stack_insert(stack_t stack, int index, void* data, int orgin)
{
    return deque_insert((deque_t)stack, index, data, orgin);
}

int stack_erase(stack_t stack, int begin, int end, int orgin)
{
    return deque_erase((deque_t)stack, begin, end, orgin);
}

int stack_read(stack_t stack, int index, void* data, int orgin)
{
    return deque_read((deque_t)stack, index, data, orgin);
}

int stack_modify(stack_t stack, int index, void* data, int orgin)
{
    return deque_modify((deque_t)stack, index, data, orgin);
}

int stack_capacity(stack_t stack)
{
    return deque_capacity((deque_t)stack);
}

int stack_alter_capacity(stack_t stack, int capacity)
{
    return deque_alter_capacity((deque_t)stack, capacity);
}

void stack_mode(stack_t stack, int mode, int set)
{
    deque_mode((deque_t)stack, mode, set);
}
